<template>
	<view>
		<view class="status-bar" :style="{ height: statusBarHeight + 'px' ,backgroundColor:backgroundColor}"></view>
	</view>
</template>

<script>
	export default {
		name: "StatusBar",
		props: {
			backgroundColor: {
				type: String,
				default: "#FFFFFF"
			},
		},
		data() {
			return {
				statusBarHeight: 0, // 保存状态栏高度
			};
		},
		created() {
			if (uni.getSystemInfoSync().platform === 'h5') {
				this.statusBarHeight = 0;
			} else {
				uni.getSystemInfo({
					success: (e) => {
						this.statusBarHeight = e.statusBarHeight;
					},
					fail: () => {
						this.statusBarHeight = 20; // 设置一个默认值
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.status-bar {
		width: 100%;
		height: 100upx;
		background: red;
	}
</style>